#include <iostream>

#include "ImageProcessing/SmallTools.h"

using namespace std;
using namespace cv;
using namespace CV_Assistant;

const string config_file = "/home/xuwj/projects/CV_Assistant/configs/ImageProcessing/params_ImgProc.yaml";

int main() {
    cv::FileStorage fSettings(config_file,CV_STORAGE_READ);
    if (!fSettings.isOpened()){
        cout<<"\nError with your config file's path!!!"<<endl;
    }

    //General Settings
    const string map_file = fSettings["MapSrc"];
    const string output_path = fSettings["ImageOutputPath"];

/**
 *  Merge AprilTag Images For Printing
 */
//    const string src1 = fSettings["ImageSrc1"];
//    const string src2 = fSettings["ImageSrc2"];
//    Mat src_a = imread(src1,IMREAD_UNCHANGED);
//    Mat src_b = imread(src2,IMREAD_UNCHANGED);
//    if(src_a.empty() || src_b.empty()){
//        cout<<"Error with your image files' path!!!"<<endl;
//    }
//    Mat dst;
//    ImageProcessing::Merge(src_a,src_b,dst,ImageProcessing::WithTop);
//    cv::namedWindow("test",WINDOW_AUTOSIZE);
//    cv::imshow("test",dst);
//    cv::waitKey(0);
//    cv::imwrite(output_path+"merge_xx.png",dst);

/**
 * 形态学操作 膨胀 填充孔洞
 */
//    cv::Mat map_img = imread(map_file, IMREAD_UNCHANGED);
//    cv::dilate(map_img,map_img,cv::Mat());
//    cv::imshow("dilated", map_img);
//    cv::waitKey(0);

/**
 * 保存图片
 */
//    cv::imwrite(output_path+"dealed.png",map_img);
//    cout<<"image saved as png.\n";

//--------------------------------------------------------------------------------------------------
/**
 *  Use Mouse-Callback To interact with image
 */
    Mat map_img = imread(map_file,IMREAD_UNCHANGED);
//    Mat map_img = imread(map_file,IMREAD_GRAYSCALE);
    string win_name = "Test_onMouse";
    auto pOnMouse = new ImageProcessing::ImageOnMouse(win_name,map_img);

    /**
     * To Show Selected Points' Pixel-Coordinates
     */
//    pOnMouse->setCB_PointCoordinate();


    /**
     * Change Selected Area 's pixel-value
     */
    pOnMouse->setCB_ChangeAreaPixelValue();

    /**
     * To Show the processing image
     */
    pOnMouse->showImage();

    /**
     * To  save  processed image.
     */
    cv::imwrite(output_path + "mouse_dealed.png", pOnMouse->image_);
    cout<<"Image saved as png.\n";

//--------------------------------------------------------------------------------------------------

/**
 *  Rotate Map To its Distinctive XY-Orientation(Orthogonal)
 */
//    Mat map_img = imread(map_file,IMREAD_UNCHANGED);
//    Mat rotated_map;
//    double canny_params[2];
//    double hough_params[5];
//    canny_params[0] = fSettings["CannyThresh1"];
//    canny_params[1] = fSettings["CannyThresh2"];
//    hough_params[0] = fSettings["HoughRho"];
//    hough_params[1] = fSettings["HoughTheta"];
//    hough_params[2] = fSettings["HoughThreshold"];
//    hough_params[3] = fSettings["HoughMinLineLength"];
//    hough_params[4] = fSettings["HoughMaxLineGap"];
//    int center_driftX = fSettings["RotateCenterDriftX"];
//    int center_driftY = fSettings["RotateCenterDriftY"];
//    hough_params[1] = hough_params[1] * CV_PI / 180.0;
//    ImageProcessing::RotateToXY(map_img,rotated_map,canny_params,hough_params,center_driftX,center_driftY);
//    cv::imwrite(output_path+"rotated.png",rotated_map);

    return 0;
}
